using System.Configuration;
using System.Data;
using System.Xml;

namespace SharePointExplorer
{
    /// <summary>
    /// Class used for add SharePoint sites List from XML file
    /// </summary>
    public sealed class ListeSharePointSitesReader
    {
        /// <summary>
        /// DataSet loaded with XML File
        /// </summary>
        private DataSet SharePointDS = null;

        /// <summary>
        /// SharePoint Server list
        /// </summary>
        public DataTable ServerList = null;
        
        /// <summary>
        /// SharePoint Sites list
        /// </summary>
        public DataTable SharepointSiteList = null;

        /// <summary>
        /// Get List SharePoint Address from XML File
        /// </summary>
        /// <returns>DataTable with all SharePoint Site Address</returns>
        private DataTable GetListAdressSharePoint()
        {
            DataTable TempTable = null;
            try
            {
                TempTable = SharePointDS.Tables[1];
            }
            catch
            {
                TempTable = new DataTable();
            }
            finally
            { }
            return TempTable;
        }

        /// <summary>
        ///  Get List SharePoint Server from XML File
        /// </summary>
        /// <returns>DataTable with all SharePoint Server Address</returns>
        private DataTable GetListServer()
        {
            DataTable TempTable = null;
            try
            {
                TempTable = SharePointDS.Tables[0];
            }
            catch
            {
                TempTable = new DataTable();
            }
            finally
            {}
            return TempTable;
        }

        /// <summary>
        /// Default constructor for load SharePoint datas from XML file
        /// </summary>
        public ListeSharePointSitesReader()
        {
            string SharePointFile = string.Empty;
            try
            {
                SharePointFile = Constantes.SHAREPOINT_LIST_FILES;
                if (SharePointFile != null)
                {
                    SharePointDS = new DataSet();
                    SharePointDS.ReadXml(SharePointFile);
                }
                   if (SharePointDS.Tables.Count > 0)
                   {
                       ServerList = GetListServer();
                       SharepointSiteList = GetListAdressSharePoint();
                   }
            }
            catch
            {
                SharePointDS = null;
                ServerList = new DataTable();
                SharepointSiteList = new DataTable();
            }
            finally
            {
                SharePointFile = null;
            }


        }

    }

}
